package com.huage_08.lesson_04;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class SendTest {
    public static void main(String[] args) throws IOException {
        //创建发送Socket对象
        DatagramSocket ds = new DatagramSocket();

        //打包要发送的数据
        Scanner sc = new Scanner(System.in);
        String data = "";
        while (!data.equals("886")){
            data = sc.nextLine();
            byte[] bytes = data.getBytes();
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length, InetAddress.getByName("192.168.56.1"),1997);

            //发送数据
            ds.send(dp);
        }
        byte[] bytes = "再见".getBytes();
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length, InetAddress.getByName("192.168.56.1"),1997);

        //发送数据
        ds.send(dp);
        //关闭Socket对象
        ds.close();
    }
}
